﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.UI;
using Silvermoon.Controls.Base;
using Silvermoon.Animations;

namespace Silvermoon.Controls.Forms
{
    public static class FormVisibilityManager
    {
        public static readonly VisualStateManager Default = new VisualStateManager(
              new VisualStateGroup(
                  new VisualState(VState.Hidden,
                      new FloatTransition { Property = FormBase.VisibilityProperty, To = 0f, Duration = 500, Tracking = TrackMode.Keep },
                      new IntTransition { Property = Control.OpacityProperty, Duration = 500, To = 0, Tracking = TrackMode.Keep }
                      ),
                  new VisualState(VState.Shown,
                      new FloatTransition { Property = FormBase.VisibilityProperty, From = 0.5f, To = 1f, Duration = 500, Tracking = TrackMode.Keep },
                      new IntTransition { Property = Control.OpacityProperty, Duration = 500, From = 0, To = 255, Tracking = TrackMode.Keep }
                  )
              )
            );

        public static readonly VisualStateManager DefaultDialog = new VisualStateManager(
          new VisualStateGroup(
              new VisualState(VState.Hidden,
                  new FloatTransition { Property = FormBase.VisibilityProperty, To = 0f, Duration = 350, Tracking = TrackMode.Keep },
                  new IntTransition { Property = Control.OpacityProperty, Duration = 350, To = 0, Tracking = TrackMode.Keep }
                  ),
              new VisualState(VState.Shown,
                  new FloatTransition { Property = FormBase.VisibilityProperty, From = 0.5f, To = 1f, Duration = 400, Tracking = TrackMode.Keep },
            //new ScaleTransition { Property = Control.ScaleProperty, From = ScaleTransform.Zero2D, To = ScaleTransform.One, Duration = 1800, FillBehavior = FillBehavior.Override, EasingFunction = new ElasticEase { Mode = EasingMode.EaseOut, Springiness = 5d } },
                  new ScaleTransition { Property = Control.ScaleProperty, From = ScaleTransform.Zero2D, To = ScaleTransform.One, Duration = 500, Tracking = TrackMode.Keep, EasingFunction = BackEase.Out },
                  new IntTransition { Property = Control.OpacityProperty, Duration = 400, From = 0, To = 255, Tracking = TrackMode.Keep }
              )
          )
          );

        public static readonly VisualStateManager PopupContextMenu = new VisualStateManager(
            new VisualStateGroup(
    new VisualState(VState.Hidden,
        new FloatTransition { Property = FormBase.VisibilityProperty, To = 0f, Duration = 350, Tracking = TrackMode.Keep },
          new IntTransition { Property = Control.OpacityProperty, Duration = 350, To = 0, Tracking = TrackMode.Keep }
        ),
    new VisualState(VState.Shown,
          new ScaleTransition { Property = Control.ScaleProperty, From = ScaleTransform.Zero2D, To = ScaleTransform.One, Duration = 500, Tracking = TrackMode.Keep, EasingFunction = BackEase.Out },
        new FloatTransition { Property = FormBase.VisibilityProperty, From = 0f, To = 1f, Duration = 600, Tracking = TrackMode.Keep },
          new IntTransition { Property = Control.OpacityProperty, Duration = 20, To = 255, Tracking = TrackMode.Keep },
        new FloatTransition { Property = PopupMenu.RelativeWidthProperty, From = 0f, To = 1f, Duration = 1, Delay = 0, Tracking = TrackMode.Keep },
        new FloatTransition { Property = PopupMenu.RelativeHeightProperty, From = 0f, To = 1f, Duration = 1, Delay = 0, Tracking = TrackMode.Keep, EasingFunction = new PowerEase { Mode = EasingMode.EaseIn, Power = 4f } }
    )
    )
    );


        public static readonly VisualStateManager DefaultContextMenu = new VisualStateManager(
            //new VisualStateGroup(
            //    new VisualState(VState.Hidden,
            //        new FloatTransition { Property = FormBase.VisibilityProperty, To = 0f, Duration = 350, Tracking = TrackMode.Keep },
            //          new IntTransition { Property = Control.OpacityProperty, Duration = 350, To = 0, Tracking = TrackMode.Keep }
            //        ),
            //    new VisualState(VState.Shown,
            //        new FloatTransition { Property = FormBase.VisibilityProperty, From = 0f, To = 1f, Duration = 600, Tracking = TrackMode.Keep },
            //          new IntTransition { Property = Control.OpacityProperty, Duration = 20, To = 255, Tracking = TrackMode.Keep },
            //        new FloatTransition { Property = ContextMenu.RelativeWidthProperty, From = 0f, To = 1f, Duration = 400, Delay = 200, Tracking = TrackMode.Keep },
            //        new FloatTransition { Property = ContextMenu.RelativeHeightProperty, From = 0f, To = 1f, Duration = 250, Delay = 400, Tracking = TrackMode.Keep, EasingFunction = new PowerEase { Mode = EasingMode.EaseIn, Power = 4f } }
            //    )
            //    )
                  new VisualStateGroup(
              new VisualState(VState.Hidden,
                  new FloatTransition { Property = FormBase.VisibilityProperty, To = 0f, Duration = 350, Tracking = TrackMode.Keep },
                  new IntTransition { Property = Control.OpacityProperty, Duration = 350, To = 0, Tracking = TrackMode.Keep }
                  ),
              new VisualState(VState.Shown,
                    new FloatTransition { Property = PopupMenu.RelativeWidthProperty, From = 0f, To = 1f, Duration = 1, Tracking = TrackMode.Keep },
                    new FloatTransition { Property = PopupMenu.RelativeHeightProperty, From = 0f, To = 1f, Duration = 1, Tracking = TrackMode.Keep, EasingFunction = new PowerEase { Mode = EasingMode.EaseIn, Power = 4f } },
                  new FloatTransition { Property = FormBase.VisibilityProperty, From = 0.5f, To = 1f, Duration = 400, Tracking = TrackMode.Keep },
                  new ScaleTransition { Property = Control.ScaleProperty, From = ScaleTransform.Zero2D, To = ScaleTransform.One, Duration = 500, Tracking = TrackMode.Keep, EasingFunction = BackEase.Out },
                  new IntTransition { Property = Control.OpacityProperty, Duration = 400, From = 0, To = 255, Tracking = TrackMode.Keep }
              )
          )

            );

        public static readonly VisualStateManager ContextMenuTransition = new VisualStateManager(
            new VisualStateGroup(
                new VisualState(VState.Hidden,
                    new FloatTransition { Property = FormBase.VisibilityProperty, To = 0f, Duration = 350, Tracking = TrackMode.Keep },
                      new IntTransition { Property = ContextMenu.WindowOpacityProperty, Duration = 350, To = 0, Tracking = TrackMode.Keep },
                     new FloatTransition { Property = ContextMenu.ContentHeightScaleProperty, Duration = 150, To = 0f, Tracking = TrackMode.Keep, EasingFunction = PowerEase.QuadraticIn },
                     new FloatTransition { Property = ContextMenu.ContentWidthScaleProperty, Duration = 1, Delay = 145, To = 0f, Tracking = TrackMode.Keep },
                     new FloatTransition { Property = ContextMenu.AnchorWindowDepthProperty, Duration = 350, To = 01, Tracking = TrackMode.Keep }
                    ),
                new VisualState(VState.Shown,
                     new FloatTransition { Property = FormBase.VisibilityProperty, From = 0.5f, To = 1f, Duration = 400, Tracking = TrackMode.Keep },
                      new IntTransition { Property = ContextMenu.WindowOpacityProperty, From = 0, To = 160, Tracking = TrackMode.Keep, Duration = 350 },
                     new FloatTransition { Property = ContextMenu.ContentWidthScaleProperty, Duration = 300, From = 0f, To = 1f, Tracking = TrackMode.Keep, EasingFunction = LinearEase.Instance },
                     new FloatTransition { Property = ContextMenu.ContentHeightScaleProperty, Duration = 200, Delay = 300, From = 0f, To = 1f, Tracking = TrackMode.Keep },
                     new FloatTransition { Property = ContextMenu.AnchorWindowDepthProperty, Duration = 450, From = 1f, To = 0.93f, Tracking = TrackMode.Keep }
                )
                )
            );

        public static readonly VisualStateManager ContextMenuTransitionWithNoZoom2 = new VisualStateManager(
    new VisualStateGroup(
        new VisualState(VState.Hidden,
             new FloatTransition { Property = ContextMenu.ContentHeightScaleProperty, Duration = 250, To = 0, Tracking = TrackMode.Keep, EasingFunction= PowerEase.In },
              new IntTransition { Property = ContextMenu.WindowOpacityProperty, Duration = 250, To = 0, Tracking = TrackMode.Keep, EasingFunction = PowerEase.Out }
            //             new FloatTransition { Property = ContextMenu.ContentHeightScaleProperty, Duration = 300, To = 0f, Tracking = TrackMode.Keep, EasingFunction = PowerEase.QuadraticIn }
            ),
        new VisualState(VState.Shown,
              new IntTransition { Property = ContextMenu.WindowOpacityProperty, From = 0, To = 190, Tracking = TrackMode.Keep, Duration = 350 },
             new FloatTransition { Property = ContextMenu.ContentHeightScaleProperty, Duration = 350, From = 0f, To = 1f, Tracking = TrackMode.Keep }
        )
        )
    );

        public static readonly VisualStateManager ContextMenuTransitionWithNoZoom = new VisualStateManager(
            new VisualStateGroup(
                new VisualState(VState.Hidden,
                    new FloatTransition { Property = FormBase.VisibilityProperty, To = 0f, Duration = 350, Tracking = TrackMode.Keep },
                      new IntTransition { Property = ContextMenu.WindowOpacityProperty, Duration = 350, To = 0, Tracking = TrackMode.Keep },
                     new FloatTransition { Property = ContextMenu.ContentHeightScaleProperty, Duration = 150, To = 0f, Tracking = TrackMode.Keep, EasingFunction = PowerEase.QuadraticIn },
                     new FloatTransition { Property = ContextMenu.ContentWidthScaleProperty, Duration = 1, Delay = 145, To = 0f, Tracking = TrackMode.Keep }
                    ),
                new VisualState(VState.Shown,
                     new FloatTransition { Property = FormBase.VisibilityProperty, From = 0.5f, To = 1f, Duration = 400, Tracking = TrackMode.Keep },
                      new IntTransition { Property = ContextMenu.WindowOpacityProperty, From = 0, To = 160, Tracking = TrackMode.Keep, Duration = 350 },
                     new FloatTransition { Property = ContextMenu.ContentWidthScaleProperty, Duration = 300, From = 0f, To = 1f, Tracking = TrackMode.Keep, EasingFunction = LinearEase.Instance },
                     new FloatTransition { Property = ContextMenu.ContentHeightScaleProperty, Duration = 200, Delay = 300, From = 0f, To = 1f, Tracking = TrackMode.Keep }
                )
                )
            );
    }
}
